package com.j180.controller;

import com.j180.excepetion.MyException;
import com.j180.excepetion.NumException;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/ex")
public class ExceptionController {

    @GetMapping("/chu/{num1}/{num2}")
    public String  chu(@PathVariable("num1") int num1,@PathVariable("num2") int num2) throws  Exception{

        if(num1<10) {
            throw new NumException("数字太小");
        }

        try {
            double result = num1 / num2;
        } catch (Exception e) {
            throw new MyException("除数不能为0");
        }

        return "";

    }

    //@ExcepetionHandler  (  处理局部异常的   只能处理当前controller中的异常  )
   // @ExceptionHandler(MyException.class)
    /*public void handlerException(MyException myException){

        System.out.println(myException.showError());

        System.out.println("发生异常时,处理异常");
    }
*/
}
